package P4树形结构;

import java.util.ArrayList;
import java.util.Comparator;

public class TestSet {
    public static void main(String[] args) {
        ArrayList<String> words = new ArrayList<>();
        FileOperation.readFile("pride-and-prejudice.txt", words);
        words.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });
        System.out.println("total = " + words.size());

        LinkedSet<String> set1 = new LinkedSet<>();
        test("LinkedSet", set1,words);

        TreeSet<String> set2 = new TreeSet<>();
        test("TreeSet",set2,words);

        TreeSet<String> set3 = new TreeSet<>();
        for (String word : words) {
            set3.add(word);
        }
        for (String word : set3) {
            System.out.println(word);
        }
    }

    private static void test(String name, Set<String> set, ArrayList<String> words) {
        System.out.println(name);
        long start  = System.currentTimeMillis();
        for (String word : words) {
            set.add(word);
        }
        System.out.println("size = " + set.size());
        for (String word : words) {
            set.remove(word);
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start + "ms");
    }
}